package com.hlz.rabbit.mq.dead;

import com.hlz.rabbit.mq.util.RabbitMqUtils;
import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 死信队列生产者
 *
 * @author Hongliang Zhu
 * @create 2022-11-21 22:15
 */
public class DeadConsumer1 {

    public static void main(String[] args) throws IOException, TimeoutException {
        try {
            Channel channel = RabbitMqUtils.getChannel();
            channel.exchangeDeclare("dead-exchange", BuiltinExchangeType.DIRECT);
            System.out.println("等待接收死信队列消息........... ");
            channel.basicConsume("dead-queue", true, new DeliverCallback() {
                @Override
                public void handle(String consumerTag, Delivery message) throws IOException {
                    String data = new String(message.getBody(), "UTF-8");
                    System.out.println(data);
                }
            }, new CancelCallback() {
                @Override
                public void handle(String consumerTag) throws IOException {

                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
